package com.zklh.leetcode.top100;

import com.zklh.leetcode.tree.model.ListNode;

/**
 * 反转链表
 *
 * @version 1.0
 * @Author tongnan
 * @Date 2023/10/23
 */
public class Solution206 {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode current = head;
        ListNode temp;
        while (current != null) {
            temp = current.next;
            current.next = prev;
            prev = current;
            current = temp;
        }
        return prev;
    }

    public static void main(String[] args) {
        Solution206 solution206 = new Solution206();
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        head.next.next.next.next = new ListNode(5);
        System.out.println(solution206.reverseList(head));
    }
}